package util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/*这段程序的作用：统计tagurl表中每个网站被抓取了几次*/

public class StatisticsWebTimes {
	public void statisticsWebTimes() { // a;sldfkja;sdjf;asjdf;asjdf
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			conn = DriverManager.getConnection("jdbc:mysql://" + host + "/"
					+ dBName + "?user=root");
			stmt = conn.createStatement();
			rs = stmt
					.executeQuery("select DISTINCT urlnotail from tagurl");
			while (rs.next()) {
				Statement stmt2 = null;
				ResultSet rs2 = null;
				Statement stmt3 = null;
				stmt2 = conn.createStatement();
				stmt3 = conn.createStatement();
				rs2 = stmt2
						.executeQuery("SELECT COUNT(*) FROM tagurl where urlnotail = '"	+ rs.getString(1) + "'");
				while (rs2.next()) {
					String sql = "insert into urlstat (url,times) values('" + rs.getString(1) + "'," + rs2.getInt("COUNT(*)") + ")";
					stmt3.executeUpdate(sql);
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	String host = null;
	String dBName = null;
	public void setHost(String host) {
		this.host = host;
	}

	public void setdBName(String dBName) {
		this.dBName = dBName;
	}

}
